<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算和，积</title>
</head>

<body>
    <script>
        // 定义函数fun，定义形参a,b,type
        function fun(a, b, type) {
            // 根据实参type来判断计算和还是积
            if (type == "+" ) {
                var res1 = a + b;
                console.log(res1);
            }else if (type == "*") {
                var res2 = a * b;
                console.log(res2)
            }else{
                console.log("你输入的格式有误，请重新输入！！！")
            }         
        };
        
        // 调用，传参
        fun (5,5,"+");
        fun (1,2,"*");
        fun(-5,-5,"+")
        fun(-5,-5,"*")
        fun (5,3,"/");



    </script>
</body>

</html>